using System;
using System.Collections.Generic;
using System.Collections;

namespace Thinxoft.HttpLib
{
    
	public class HttpApplicationContext : MarshalByRefObject, IHttpApplicationContext
	{
        Hashtable data = new Hashtable();

        public void Add(object key, object val)
		{
			if(data.ContainsKey(key))
				data[key] = val;
			else
				data.Add(key,val);
		}

		public void Remove(object key)
		{
			data.Remove(key);
		}

		public IDictionaryEnumerator GetEnumerator()
		{
			return data.GetEnumerator();
		}

		public int Count
		{
			get
			{
				return data.Count;
			}
		}

		public object this[object key]
		{
			get
			{
				return data[key];
			}set
			 {
				 if(data.ContainsKey(key))
				 {
					 data[key] = value;
				 }
				 else
				 {
					 data.Add(key,value);
				 }
			 }
		}

		public IHttpSession CreateNewSession(string sessionId)
		{
			HttpSession session = new HttpSession();
			session.SetId(sessionId);
			data.Add(sessionId,session);
			return (IHttpSession)data[sessionId];
		}
	}
}
